package com.ruoyi.pingan.fymodule.goodsinfo.goods.provider;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.pingan.fymodule.goodsinfo.goods.api.SxoGoodsApi;
import com.ruoyi.pingan.fymodule.goodsinfo.goods.entity.SxoGoods;
import com.ruoyi.pingan.fymodule.goodsinfo.goods.service.SxoGoodsService;
import com.ruoyi.pingan.fymodule.goodsinfo.goods.vo.SxoGoodsApiVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class SxoGoodsProvider implements SxoGoodsApi {
    @Autowired
    private SxoGoodsService sxoGoodsService;

    @Override
    public SxoGoodsApiVo findGoods(String id) {
        SxoGoods sysUser = sxoGoodsService.getById(id);
        if (ObjectUtil.isNotEmpty(sysUser)) {
            SxoGoodsApiVo vo = new SxoGoodsApiVo();
            BeanUtil.copyProperties(sysUser, vo);
            return vo;
        }
        return null;
    }

    @Override
    public List<SxoGoodsApiVo> listGoods(List<String> id) {
        List<SxoGoods> list = sxoGoodsService.listByIds(id);
        if (list.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        return list.stream().map(sysUser -> {
            SxoGoodsApiVo vo = new SxoGoodsApiVo();
            BeanUtil.copyProperties(sysUser, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}
